package com.asion.service.impl;

import com.asion.domain.Detail;
import com.asion.domain.Video;
import com.asion.mapper.DetailMapper;
import com.asion.mapper.VideoMapper;
import com.asion.service.DetailService;
import com.asion.vo.VideoVo;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.github.yulichang.wrapper.MPJLambdaWrapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
@Service
public class DetailServiceImpl implements DetailService {

    @Autowired
    private DetailMapper detailMapper;
    @Autowired
    private VideoMapper videoMapper;

    @Override
    public VideoVo selectOne(String id) {


        // 测试联表查询
        VideoVo one = detailMapper.selectJoinOne(VideoVo.class,
                new MPJLambdaWrapper<Detail>()
                        .selectAll(Detail.class)
                        .selectAsClass(Video.class,VideoVo.class)
                        .leftJoin(Video.class, Video::getId,Detail::getId)
                        .eq(Detail::getId, id));
        return one;
    }

    @Override
    public VideoVo selectOneByName(String name) {
        QueryWrapper<Video> wrapper = new QueryWrapper<Video>().eq("vod_name",name);
        Video video = videoMapper.selectOne(wrapper);
        if(video == null){
            return null;
        }
        Integer id = video.getId();
        VideoVo one = detailMapper.selectJoinOne(VideoVo.class,
                new MPJLambdaWrapper<Detail>()
                        .selectAll(Detail.class)
                        .selectAsClass(Video.class,VideoVo.class)
                        .leftJoin(Video.class, Video::getId,Detail::getId)
                        .eq(Detail::getId, id));
        return one;
    }

}
